<form class="form-inline" id="order_list_form">
	<div class="form-group">
		<div class="input-group">
			<div class="input-group-addon"> 订单ID</div>
			<input type="text" class="form-control" name="id" />
		</div>
	</div>
	<div class="form-group">
		<div class="input-group">
			<div class="input-group-addon"> 订单名称</div>
			<input type="text" class="form-control" name="name" />
		</div>
	</div>
	<div class="form-group">
		<div class="input-group">
			<div class="input-group-addon"> 商品ID</div>
			<input type="text" class="form-control" name="productId" />
		</div>
	</div>
	<div class="form-group">
		<div class="input-group">
			<div class="input-group-addon"> 商品Code</div>
			<input type="text" class="form-control" name="productCode" />
		</div>
	</div>
	<br/>
	<div class="form-group">
		<div class="input-group">
			<div class="input-group-addon"> 用户登录名</div>
			<input id="userName" type="text" name="userName" class="form-control" style="width:150px;" />
		</div>
	</div>

	<div class="form-group">
		<div class="input-group">
			<div class="input-group-addon">创建时间</div>
			<input type="text" class="form-control" name="createStartTime" id="order_create_time" />
			<div class="input-group-addon">-</div>
			<input type="text" class="form-control" name="createEndTime" id="order_End_time" />
		</div>
	</div>
	<div class="input-group">
		<div class="input-group-addon"> 订单状态</div>
		<select id="orderStatus" name="status" class="form-control">
			<option value="-1" selected="selected">全部</option>
			<option value="0">新建未支付</option>
			<option value="1">已支付</option>
			<option value="2">支付失败</option>
			<option value="3">创建商城订单失败</option>
			<option value="4">生成场景失败</option>
		</select>
	</div>
	<div class="input-group">
		<div class="input-group-addon">订单类型</div>
		<select id="payType" name="payType" class="form-control">
			<option value="0" selected="selected">全部</option>
			<option value="1">充值订单</option>
			<option value="2">消耗订单</option>
			<option value="3">爆款订单</option>
			<option value="4">直充订单</option>
			<option value="5">去尾页</option>
			<option value="6">查看场景数据</option>
		</select>
	</div>
	
	<br>
	<button type="button" class="btn btn-primary" onclick="query_order_list('#order_list_grid', '/m/ie/order/list.json')">查询</button>
</form>
<form class="form-inline">
	<div class="input-group">
		<div class="input-group-addon">订单总数</div>
		<input type="text" id="orderCount" readonly="readonly" class="form-control" name="orderCount" maxlength="50" style="width: 100px;">
	</div>
	<div class="input-group">
		<div class="input-group-addon">订单总金额(元)</div>
		<input type="text" id="totalAmount" readonly="readonly" class="form-control" name="totalAmount" maxlength="50" style="width: 100px;">
	</div>
	<div class="input-group">
		<div class="input-group-addon">总用户数</div>
		<input type="text" id="totalUsers" readonly="readonly" class="form-control" name="totalUsers" maxlength="50" style="width: 100px;">
	</div>
</form>
<table id="order_list_grid" data-toggle="table" data-toolbar="#order_list_form" data-unique-id="id" data-query-params="order_query_params" data-click-to-select="true" data-page-size="10">
	<thead>
		<tr>
			<th data-field="id">订单ID</th>
			<th data-field="name">订单名称</th>
			<th data-field="totalFee">订单总价</th>
			<th data-field="productId" data-formatter="tpl_formatter_id">商品ID</th>
			<th data-field="productCode">样例code</th>
			<th data-field="status" data-formatter=formatter_status>状态</th>
			<th data-field="loginName">登录名</th>
			<th data-field="channel" data-formatter="channel_formatter">订单渠道</th>
			<th data-field="payType" data-formatter="tpl_formatter_payType">订单类型</th>
			<th data-field="createTime" data-formatter="log_formatter_time">创建时间</th>
			<th data-field="outOrderId">支付订单ID</th>
			<th data-field="mallOrderId">商城订单ID</th>
			<th data-field="remark">备注</th>
		</tr>
	</thead>
</table>

<!-- /.modal -->
<script type="text/javascript">
	var order_status = { '0':'新建未支付','1': '已支付', '2': '回调错误', '3':'创建商城订单失败','4':'生成场景失败' };
	$(document).ready(function() {
		///日期控件
		$('#order_create_time,#order_End_time').datetimepicker();
		//订单类型下拉框
	});

	function formatter_status(cellvalue, rowObject) {
		if(order_status[cellvalue]) {
			cellvalue = order_status[cellvalue];
		}
		return cellvalue;
	}

	//查询
	function query_order_list(id, url) {
			$(id).bootstrapTable('refresh', { url: url });
			getStatNumbers();
	}
	
	function getStatNumbers(){
			$.ajax({
			url: "/m/ie/order/numbers",
			type: "POST",
			data: $('#order_list_form').serialize(),
			success: function(data, ts, xhr) {
				$('#orderCount').val(data.orderCount);
				$('#totalAmount').val(data.totalAmount);
				$('#totalUsers').val(data.totalUsers);
			}
		});
	}
	function order_query_params(params) {
		$('#order_list_form :input').each(function() {
			if($(this).attr('name')) {
				params[$(this).attr('name')] = $(this).val();
			}
		});
		return params;
	}

	function log_formatter_time(value) {
		return new Date(value).format('yyyy-MM-dd hh:mm:ss');
	}

	//商品平台
	var product_channel = {
		'EDITOR': 'EDITOR',
		'PC': 'PC',
		'21': 'IOS',
		'22': '安卓'
	};

	function channel_formatter(cellvalue, rowObject) {
		if(product_channel[cellvalue]) {
			cellvalue = product_channel[cellvalue];
		}
		return cellvalue;
	}

	function tpl_formatter_id(value, o) {
		return '<a target="_blank" href="http://store.eqxiu.com/' + o.productId + '.html">' + value + '</a>';
	}
	
	function tpl_formatter_payType(value, o) {
		if(value == 1 ) return "充值订单" ;
		else if(value == 2) return "消耗订单";
		else if(value == 3) return "爆款订单";  
		else if(value == 4) return "直充订单";  
		else if(value == 5) return "去尾页订单";  
		else if(value == 6) return "场景数据订单";  
	}
	
	
	
</script>